import os,re,sys
ext="jpg"
if sys.argv.__len__()==2:
	ext=sys.argv[1]
for file_name in os.listdir(os.getcwd()):
	if file_name[-5:]!=".html" and file_name[-4:]!=".htm":
		continue
	print file_name
	f=file(file_name)
	p=re.compile(r"\"[^\"]*\.%s\"" % ext)
	ct=1
	os.mkdir(ext)
	for line in f:
		ss=p.findall(line)
		for s in ss:
			s=s[1:s.__len__()-1]
			s=re.sub(r"/",r"\\",s)
			s=os.getcwd()+"\\"+s
			new_file_name=os.getcwd()+"\\%s\\%d.%s" % (ext,ct,ext)

			ct+=1
			print ct;
			print s,new_file_name
			try:
				os.rename(s,new_file_name)
			except:
				pass

